<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="ISO-8859-1">
<title>海科集团任务监督管理系统-督办管理</title>
<style>
#center {
	/* 	width: 1100px; */
	margin: 0 auto;
}

#divCurrent {
	float: left;
	margin-left: 10px;
}

#divUserNameGrid {
	float: left;
	margin-left: 10px;
}

#divRadio {
	margin-left: 10px;
}

#divUserName {
	margin: 0 0 5px 15px;
}

#divOrg {
	float: left;
	margin-left: 10px;
	/* 	display: none; */
}

#divUsers {
	float: left;
	margin-left: 10px;
}

#divTool {
	float: left;
	margin-right: 10px;
}

#divRight {
	position: relative;
	left: 10px;
	top: 120px;
}

#divLeft {
	position: relative;
	left: 10px;
	top: 150px;
}

#currentweek {
	width: 100px;
}

.clear {
	clear: left;
}
</style>
<!-- 按钮 -->
<style type="text/css">
.button {
	border: none;
	color: white;
	padding: 3px 3px;
	text-align: center;
	text-decoration: none;
	display: inline-block;
	font-size: 14px;
	margin: 1px 1px;
	cursor: pointer;
	border-radius: 8px;
	width: 70px;
}

.button:hover {
	opacity: 0.7;
}

#npvbtn {
	background-color: Green; /* Green */
}

#irrbtn {
	background-color: Green; /* Green */
}
</style>
<style>
#dlgTable tr {
	height: 50px;
}
</style>
</head>
<body>
	<%@ include file="TaskHeader.jsp"%>
	<script>
		var PUser = JSON.parse('${sysUser}');
		$(document).ready(function() {
			$("#surpvise a .out").stop().animate({
				'top' : '48px'
			}, 300); // move down - hide
			$("#surpvise a .over").stop().animate({
				'top' : '0px'
			}, 300); // move down - show
		});
	</script>
	<div id="center">
		<div style="margin: 20px 0;"></div>
		<div style="margin-bottom: 15px;">

			<div style="float: left; margin: 10px;">
				<!-- 				<span>工作名称：<input name="queryname" id="queryname" -->
				<!-- 					class="easyui-textbox" style="width: 180px;"></span> <a -->
				<!-- 					href="javascript:void(0)" class="easyui-linkbutton" -->
				<!-- 					onclick="queryForm()" style="width: 80px">查询</a>  -->
				<!-- 				<button onclick="npvclick()" class="button" id="npvbtn">未完成</button> -->
				<!-- 				<button onclick="irrclick()" class="button" id="irrbtn">已完成</button> -->
				<!-- 				<input id="state" type="hidden" /> -->
				<a href="javascript:void(0)" onclick="backweek()">上一周</a>&nbsp;&nbsp;&nbsp;<span
					id="currentyear">${currentyear}</span>年第<span id="currentweek">${currentweek}</span>周&nbsp;&nbsp;&nbsp;<a
					href="javascript:void(0)" onclick="nextweek()">下一周</a><input
					id="currentdate" type="hidden" value="${currentdate}" />
			</div>
			<div style="float: left;">
				<select class="easyui-combobox" name="state" id="state" label=""
					labelPosition="left" style="width: 180px;">
					<option value="0">未完成</option>
					<option value="1">已完成</option>
					<!-- 					<option value="all">全部</option> -->
				</select>&nbsp;&nbsp;&nbsp;
			</div>
			<div style="float: left; margin-bottom: 5px;">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="newMeet()" style="width: 90px">新建会议</a>&nbsp;
			</div>
			<div style="float: right; margin: 0 50px 0 0;">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="newForm()" style="width: 120px">新建督办事项</a>
			</div>
		</div>
		<br>
		<div class="clear"></div>
		<div>
			<table>
				<tr>
					<td>
						<div id="divwest" style="margin: 0 10px 0 0;">
							<table class="easyui-datagrid" id="ttmeet">
							</table>
						</div>
					</td>
					<td>
						<div id="diveast" style="margin: 0 0 0 10px;">
							<table class="easyui-datagrid" id="tttask">
							</table>
						</div>
					</td>
			</table>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 800px; height: 500px;"
		data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
		<form id="fm" method="post" novalidate
			style="margin: 0; padding: 20px 50px">
			<table id="dlgTable">
				<tr>
					<td><span>会议名称:</span></td>
					<td><input name="taskMettingName" id="taskMettingName"
						class="easyui-textbox" required="true"
						data-options="editable:false" style="width: 400px;"><br></td>
				</tr>
				<tr>
					<td><span>督办事项:</span></td>
					<td><input name="taskname" id="taskname"
						class="easyui-textbox" required="true" style="width: 400px;"><br></td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">责任组织机构：</div>
					</td>
					<td><input class="easyui-combotree" id="userdept"
						style="width: 230px" required="true" /></td>
				</tr>
				<tr>
					<td><span>执行人:</span></td>
					<td><input name="exename" id="exename" class="easyui-textbox"
						required="true" style="width: 300px;"><a id="exenameBtn"
						href="javascript:void(0)" class="easyui-linkbutton"
						onclick="exeForm()" style="width: 80px">选择</a></td>
				</tr>
				<tr>
					<td style="width: 120px;"><span>计划完成时间:</span></td>
					<td><input class="easyui-datebox" id="datePlan"
						style="width: 180px;"> <br /></td>
				</tr>
				<tr>
					<td><span>备注:</span></td>
					<td><textarea name="taskinfo" id="taskinfo" cols="60" rows="3"
							style="OVERFLOW: hidden"></textarea><br></td>
				</tr>
			</table>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-save" onclick="save()" style="width: 90px">保存</a> <a
			href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="commit()" style="width: 90px">提交</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')"
			style="width: 90px">关闭</a>
	</div>

	<div id="dlgMeet" class="easyui-dialog"
		style="width: 500px; height: 300px;"
		data-options="closed:true,modal:true,border:'thin',buttons:'#dlgMeet-buttons'">
		<form id="fmMeet" method="post" novalidate
			style="margin: 0; padding: 20px 50px">
			<table id="dlgTable">
				<tr>
					<td><span>会议名称:</span><input id="infid" type="hidden" /></td>
					<td><input name="mettingName" id="mettingName"
						class="easyui-textbox" required="true" style="width: 300px;"><br></td>
				</tr>
			</table>
		</form>
	</div>
	<div id="dlgMeet-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-save" onclick="saveMeet()" style="width: 90px">保存</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#dlgMeet').dialog('close')"
			style="width: 90px">关闭</a>
	</div>

	<div id="dlgExe" class="easyui-dialog"
		style="width: 660px; height: 560px;"
		data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttonsExe'">
		<form id="fmExe">
			<div id="divRadio">
				<input type="radio" name="radioExe" value="1" checked
					onchange="radioexechange()" />最近 <input type="radio"
					name="radioExe" value="2" onchange="radioexechange()" />组织机构
			</div>
			<div id="divUserName">
				<span>姓名：<input name="queryname" id="queryname"
					class="easyui-textbox" style="width: 100px;"></span> <a
					href="javascript:void(0)" class="easyui-linkbutton"
					onclick="queryUserName()" style="width: 80px">查询</a>
			</div>
			<div id="divUserNameGrid">
				<table class="easyui-datagrid" id="ttUserName" title="">
				</table>
			</div>
			<div id="divCurrent">
				<table class="easyui-datagrid" id="ttCurrent" title="最近联系人">
				</table>
			</div>
			<div id="divOrg">
				<table class="easyui-treegrid" id="ttOrg" title="组织机构"></table>
			</div>
			<div id="divTool">
				<div id="divRight">
					<a href="javascript:void(0)" class="easyui-linkbutton c6"
						onclick="adduser()" style="width: 30px">添加</a>
				</div>
				<div id="divLeft">
					<a href="javascript:void(0)" class="easyui-linkbutton c6"
						onclick="deluser()" style="width: 30px">删除</a>
				</div>
			</div>
			<div id="divUsers">
				<table class="easyui-datagrid" id="ttUsers" title="已选联系人">
				</table>
			</div>
		</form>
	</div>
	<div id="dlg-buttonsExe">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveExe()" style="width: 90px">确定</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#dlgExe').dialog('close')" style="width: 90px">关闭</a>
	</div>
	<div class="loadinghk">
		<div style="top: 50%; left: 50%; position: absolute;">
			<img src="resourse/img/load.gif" />
		</div>
	</div>

	<div id="dlgTransfer" class="easyui-dialog"
		style="width: 500px; height: 380px;"
		data-options="closed:true,modal:true,border:'thin'">
		<table class="easyui-datagrid" id="ttTransfer">
		</table>
	</div>
	<div id="dlgDelayList" class="easyui-dialog"
		style="width: 700px; height: 300px;"
		data-options="closed:true,modal:true,border:'thin'">
		<table class="easyui-datagrid" id="tttaskDelayList">
		</table>
	</div>
	<script>
		var isTransfer = '1';
		//获取当前时间，格式YYYY-MM-DD
		function getNowFormatDate() {
			var date = new Date();
			var seperator1 = "-";
			var year = date.getFullYear();
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = year + seperator1 + month + seperator1 + strDate;
			return currentdate;
		}
	</script>
	<!-- 主窗体 -->
	<script>
		$(function() {
			bindgridmeet();
			initcob();
			// 			npvclick();
			bindgrid();
			bindgridcurrent();
			// 			bindtreeorg();
			// 			bindgriduser();
			radioexechange();
			binduserdept();
			$('#center').width($(window).width() - 50);
		})
		//未完成
		function npvclick() {
			$('#irrbtn').css("opacity", "0.3");
			$('#npvbtn').css("opacity", "1");
			$('#state').val(0);
			bindgridmeet();
		}
		//已完成
		function irrclick() {
			$('#irrbtn').css("opacity", "1");
			$('#npvbtn').css("opacity", "0.3");
			$('#state').val(1);
			bindgridmeet();
		}
		function initcob() {
			$("#state").combobox({
				'editable' : false,
				onChange : function(n, o) {
					bindgridmeet();
				}
			});
		}
		function binduserdept() {
			$('#userdept').combotree({
				url : 'api/DeptManage/DeptListJson_combobox?deptid=982ce640-1567-4b68-a324-4aa5bd1f1804',
				onLoadSuccess : function() {
					$('#userdept').combotree('tree').tree("collapseAll");
				}
			});
		}
		function bindgrid() {
			$('#tttask')
					.datagrid(
							{
								title : '督办事项列表',
								nowrap : false,
								rownumbers : true,
								singleSelect : true,
								width : $(window).width() - 630,
								height : 480,
								pagination : true,
								url : 'SurpviseManage/SurpviseListJson',
								queryParams : {
									"queryname" : $('#queryname').val(),
									"infId" : $('#infid').val()
								},
								method : 'get',
								columns : [ [
										{
											field : 'PRO_CONTENT',
											title : '督办事项',
											width : 280,
											formatter : function(val, rec) {
												return val;
											}
										},
										{
											field : 'PRO_COEE',
											title : '整体进度',
											// 					width : 200,
											formatter : function(val, rec) {
												if (val == null) {
													val = 0;
												}
												var tempval = val;
												var htmlstr = '';
												var flag = false;
												//判断是否超期
												if (rec.PRO_VALIDATETIME == null
														&& rec.PRO_PLANFINISHDATE < getNowFormatDate()) {
													flag = true;//当没有完成时间时，与当前时间比较
												}
												if (rec.PRO_VALIDATETIME != null
														&& rec.PRO_PLANFINISHDATE < rec.PRO_VALIDATETIME
																.substr(0, 10)) {
													flag = true;//当有完成时间时，与完成时间比较
												}
												if (flag) {
													htmlstr = '<div class="easyui-progressbar progressbar" style="width: 60px; " value="'
															+ tempval
															+ '" text="'
															+ tempval
															+ '%">'
															+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;color:red;font-weight:bold; ">'
															+ tempval
															+ '%</div>'
															+ '<div class="progressbar-value" style="width: '
															+ tempval
															+ '%; height: 20px; line-height: 20px; color:red;font-weight:bold;">'
															+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;color:red;font-weight:bold;">'
															+ tempval
															+ '%</div>'
															+ '</div>'
															+ '</div>';
												} else {
													htmlstr = '<div class="easyui-progressbar progressbar" style="width: 60px; " value="'
															+ tempval
															+ '" text="'
															+ tempval
															+ '%">'
															+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;">'
															+ tempval
															+ '%</div>'
															+ '<div class="progressbar-value" style="width: '
															+ tempval
															+ '%; height: 20px; line-height: 20px;">'
															+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;">'
															+ tempval
															+ '%</div>'
															+ '</div>'
															+ '</div>';
												}
												return htmlstr;
											}
										},
										{
											field : 'PRO_EXECUTEUSERNAME',
											title : '执行人',
											width : 60,
											formatter : function(val, rec) {
												return val == null ? "" : val;
											}
										},
										// 										{
										// 											field : 'PRO_RESULT',
										// 											title : '备注',
										// 											width : 100,
										// 											formatter : function(val, rec) {
										// 												return val == null ? "" : val;
										// 											}
										// 										},
										{
											field : 'PRO_PLANFINISHDATE',
											title : '计划完成日期',
											width : 90,
											formatter : function(val, rec) {
												return val == null ? "" : val
														.substr(0, 10);
											}
										},
										{
											field : 'PRO_EXETIME',
											title : '提交时间',
											width : 90,
											formatter : function(val, rec) {
												return val == null ? "" : val
														.substr(0, 10);
											}
										},
										{
											field : 'PRO_EXECUTEDEPTNAME',
											title : '责任组织',
											width : 120,
											formatter : function(val, rec) {
												return val;
											}
										},
										{
											field : 'edit',
											title : '',
											width : 38,
											formatter : function(val, rec,
													index) {
												if (rec.PRO_EXETIME != null) {
													return '编辑';
												} else {
													var str = '<a href="javascript:void(0)" onclick="editForm('
															+ index
															+ ')">编辑</a>';
													return str;
												}
											}
										},

										{
											field : 'del',
											title : '',
											width : 38,
											formatter : function(val, rec,
													index) {
												if (rec.PRO_EXETIME != null) {
													return '删除';
												} else {
													var str = '<a href="javascript:void(0)" onclick="delForm('
															+ index
															+ ')">删除</a>';
													return str;
												}
											}
										},
										{
											field : 'close',
											title : '',
											width : 38,
											formatter : function(val, rec,
													index) {
												if (rec.PRO_OVERDUE != '2') {
													var str = '<a href="javascript:void(0)" onclick="closeForm('
															+ index
															+ ')">完成</a>';
													return str;
												} else {
													return '完成';
												}
											}
										},
										{
											field : 'delayList',
											title : '',
											width : 65,
											formatter : function(val, rec,
													index) {
												var str = '<a href="javascript:void(0)" onclick="delayFormList('
														+ index + ')">延期记录</a>';
												return str;
											}
										} ] ],
								toolbar : [],
								onLoadSuccess : function() {
								},
								onDblClickRow : function() {
								}
							});
		}
	</script>
	<script>
		function bindgridDelay(row) {
			$('#tttaskDelayList').datagrid({
				title : '',
				nowrap : false,
				rownumbers : true,
				singleSelect : true,
				collapsible : true,
				width : 500,
				height : 200,
				// 				pagination : true,
				url : 'task/selectTasksDelay',
				queryParams : {
					"proId" : row["PRO_ID"]
				},
				method : 'get',
				columns : [ [ {
					field : 'LEV_RESON',
					title : '申请原因'
				}, {
					field : 'LEV_OLDDATE',
					title : '修改前时间',
					formatter : function(val, rec) {
						return val;
					}
				}, {
					field : 'LEV_NEWDATE',
					title : '修改后时间',
					formatter : function(val, rec) {
						return val;
					}
				} ] ]
			})
		}
		function delayFormList(rowindex) {
			$('#dlgDelayList').dialog('open').dialog('center').dialog(
					'setTitle', '延期申请列表');
			var rows = $('#tttask').datagrid("getRows");
			var row = rows[rowindex];
			bindgridDelay(row);
		}
	</script>
	<!-- 	meet -->
	<script>
		function bindgridmeet() {
			$('#infid').val('');
			$('#ttmeet')
					.datagrid(
							{
								title : '会议列表',
								nowrap : false,
								rownumbers : true,
								singleSelect : true,
								width : 560,
								height : 480,
								pagination : true,
								url : 'SurpviseManage/meetListJson',
								queryParams : {
									"state" : $('#state').combobox('getValue')
								},
								method : 'get',
								columns : [ [
										{
											field : 'INF_METTINGNAME',
											title : '会议名称',
											width : 230,
											formatter : function(val, rec) {
												var str = '<a target="_blank" href="SurpviseManage/surpviseView?inf_id='
														+ rec.INF_ID
														+ '&year='
														+ $('#currentyear')
																.text()
														+ '&week='
														+ $('#currentweek')
																.text()
														+ '">'
														+ val + '</a>';
												return str;
											}
										},
										{
											field : 'INF_CREATTIME',
											title : '创建时间',
											width : 90,
											formatter : function(val, rec) {
												return val == null ? "" : val
														.substr(0, 10);
											}
										},
										{
											field : 'edit',
											title : '',
											width : 40,
											formatter : function(val, rec,
													index) {
												if ($('#state').combobox(
														'getValue') == '0') {
													var str = '<a href="javascript:void(0)" onclick="editMeet('
															+ index
															+ ')">编辑</a>';
													return str;
												} else {
													return '编辑';
												}
											}
										},
										{
											field : 'del',
											title : '',
											width : 40,
											formatter : function(val, rec,
													index) {
												if ($('#state').combobox(
														'getValue') == '0') {
													var str = '<a href="javascript:void(0)" onclick="delMeet('
															+ index
															+ ')">删除</a>';
													return str;
												} else {
													return '删除';
												}
											}
										},
										{
											field : 'transfer',
											title : '',
											width : 40,
											formatter : function(val, rec,
													index) {
												var str = '<a href="javascript:void(0)" onclick="transferMeet('
														+ index + ')">抄送</a>';
												return str;
											}
										},
										{
											field : 'transferr',
											title : '',
											width : 80,
											formatter : function(val, rec,
													index) {
												var str = '<a href="javascript:void(0)" onclick="transferRecord('
														+ index + ')">抄送记录</a>';
												return str;
											}
										} ] ],
								toolbar : [],
								onLoadSuccess : function() {
								},
								onClickRow : function(index, row) {
									$('#infid').val(row.INF_ID);
									bindgrid();
								}
							});
		}

		function newMeet() {
			$('#dlgMeet').dialog('open').dialog('center').dialog('setTitle',
					'新建会议');
			$('#fmMeet').form('clear');
			$('#infid').val();
		}

		function editMeet(rowindex) {
			var rows = $('#ttmeet').datagrid("getRows");
			var row = rows[rowindex];
			$('#dlgMeet').dialog('open').dialog('center').dialog('setTitle',
					'会议编辑');
			$('#fmMeet').form('clear');
			$('#infid').val(row['INF_ID']);
			$('#mettingName').textbox('setText', row['INF_METTINGNAME']);
		}

		function saveMeet() {
			if (!$('#fmMeet').form('validate')) {
				return;
			}
			$('.loadinghk').show();
			$.ajax({
				type : "post",
				url : "SurpviseManage/saveMeet",
				data : {
					id : $('#infid').val(),
					meetingname : $('#mettingName').textbox('getText')
				},
				success : function(data) {
					if (data != '保存失败!') {
						$('#infid').val(data);
						$.messager.alert('消息', "保存成功");
					}
					$('#dlgMeet').dialog('close');
					bindgridmeet();
					bindgridcurrent();
					// 					bindgriduser();
					$('.loadinghk').hide();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$('.loadinghk').hide();
					$.messager.alert('消息', errorThrown);
				}
			});
		}

		function delMeet(rowindex) {
			var child = hasChild(rowindex);
			if (child > 0) {
				$.messager.alert('消息', '请先删除该会议下所有督办事项');
				return;
			}
			$.messager.confirm('请确认', '删除后无法恢复，确认删除?', function(r) {
				if (r) {
					var rows = $('#ttmeet').datagrid("getRows");
					var row = rows[rowindex];
					$.ajax({
						type : "post",
						url : "SurpviseManage/delMeet",
						data : {
							inf_id : row['INF_ID'],
						},
						success : function(data) {
							$.messager.alert('消息', data);
							if (data == '删除成功!') {
								bindgrid();
								bindgridmeet();
							}
						},
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {
							$.messager.alert('消息', errorThrown);
						}
					});
				}
			});
		}

		function transferMeet(rowindex) {
			isTransfer = 1;
			bindgridcurrent();
			bindgriduser();
			$('#dlgExe').dialog('open').dialog('center').dialog('setTitle',
					'选择抄送人');
			$('input:radio:first').attr('checked', 'true');
		}

		function transferRecord(rowindex) {
			var rows = $('#ttmeet').datagrid("getRows");
			var row = rows[rowindex];
			$('#dlgTransfer').dialog('open').dialog('center').dialog(
					'setTitle', '抄送记录');
			bindgridTransfer(row);
		}
		//抄送
		function saveTransfer() {
			$.messager.confirm('请确认', '确定抄送?', function(r) {
				if (r) {
					var row = $('#ttmeet').datagrid('getSelected');
					$.ajax({
						type : "post",
						url : "SurpviseManage/saveTransfer",
						data : {
							infId : row['INF_ID'],
							exeusers : JSON.stringify($('#ttUsers').datagrid(
									'getRows'))
						},
						success : function(data) {
							$.messager.alert('消息', data);
							$('#dlgExe').dialog('close');
						},
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {
							$.messager.alert('消息', errorThrown);
						}
					});

				}
			});

		}
		//判断是否有督办事项，有则不可删除会议
		function hasChild(rowindex) {
			var rows = $('#ttmeet').datagrid("getRows");
			var row = rows[rowindex];
			var result = 0;
			$.ajax({
				async : false,//使用同步的方式,true为异步方式
				type : "post",
				url : "SurpviseManage/hasChild",
				data : {
					infId : row['INF_ID'],
				},
				success : function(data) {
					result = data;
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$.messager.alert('消息', errorThrown);
				}
			});
			return result;
		}
		function closeForm(rowindex) {
			var rows = $('#tttask').datagrid("getRows");
			var row = rows[rowindex];
			if (row["PRO_COEE"] != 100) {
				$.messager.alert('消息', '请先将进度设置为100%');
				return;
			}
			$.messager.confirm('请确认', '确认完成?', function(r) {
				if (r) {
					$.ajax({
						type : "post",
						url : "SurpviseManage/closeSurpvise",
						data : {
							infId : row['INF_ID'],
							proId : row['PRO_ID'],
							userId : row['PRO_EXECUTEUSERID']
						},
						success : function(data) {
							$.messager.alert('消息', data);
							if (data == '操作完成!') {
								bindgrid();
								bindgridmeet();
							}
						},
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {
							$.messager.alert('消息', errorThrown);
						}
					});
				}
			});
		}
		function bindgridTransfer(row) {
			$('#ttTransfer').datagrid({
				title : '',
				singleSelect : true,
				width : 450,
				height : 300,
				url : 'SurpviseManage/transferListJson',
				queryParams : {
					infId : row['INF_ID'],
				},
				columns : [ [ {
					field : 'TRA_RECEIVENAME',
					title : '抄送人',
					width : 180,
					formatter : function(val, rec) {
						return val;
					}
				}, {
					field : 'TRA_TIME',
					title : '抄送时间',
					width : 150,
					formatter : function(val, rec) {
						return val;
					}
				} ] ],
				onDblClickRow : function() {
				}
			});
		}
	</script>
	<!-- 	督办主窗体按钮事件 -->
	<script>
		function backweek() {
			$.ajax({
				type : "post",
				url : "SurpviseManage/backWeek",
				data : {
					currentyear : $('#currentyear').val(),
					currentweek : $('#currentweek').val(),
					currentdate : $('#currentdate').val()
				},
				success : function(data) {
					$('#currentyear').text(data.year);
					$('#currentweek').text(data.week);
					$('#currentdate').val(data.date);
					bindgridmeet();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$.messager.alert('消息', errorThrown);
				}
			});
		}
		function nextweek() {
			$.ajax({
				type : "post",
				url : "SurpviseManage/nextWeek",
				data : {
					currentyear : $('#currentyear').val(),
					currentweek : $('#currentweek').val(),
					currentdate : $('#currentdate').val()
				},
				success : function(data) {
					$('#currentyear').text(data.year);
					$('#currentweek').text(data.week);
					$('#currentdate').val(data.date);
					bindgridmeet();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$.messager.alert('消息', errorThrown);
				}
			});
		}
		function newForm() {
			if ($('#infid').val() == '') {
				$.messager.alert('消息', '请先选择会议');
				return;
			}
			if ($('#state').combobox('getValue') == 1) {
				$.messager.alert('消息', '请选择未完成会议');
				return;
			}
			isTransfer = 0;
			bindgridcurrent();
			bindgriduser();
			$('#dlg').dialog('open').dialog('center').dialog('setTitle',
					'新建督办任务');
			$('#fm').form('clear');
			$('#exenameBtn').linkbutton('enable');
			var row = $('#ttmeet').datagrid('getSelected');
			$('#taskMettingName').textbox('setText', row['INF_METTINGNAME']);
			$('#tttask').datagrid('clearSelections');
		}
		function editForm(rowindex) {
			var rows = $('#tttask').datagrid("getRows");
			var row = rows[rowindex];
			$('#dlg').dialog('open').dialog('center').dialog('setTitle',
					'督办任务编辑');
			$('#fm').form('clear');

			var rowm = $('#ttmeet').datagrid('getSelected');
			$('#taskMettingName').textbox('setText', rowm['INF_METTINGNAME']);
			$('#infid').val(row['INF_ID']);
			$('#taskname').textbox('setText', row['PRO_CONTENT']);
			$('#taskinfo').val(row['PRO_RESULT']);
			$('#datePlan').datebox('setValue', row['PRO_PLANFINISHDATE']);
			$('#exename').textbox('setText', row['PRO_EXECUTEUSERNAME']);
			$('#exename').textbox('readonly', true);
			$('#userdept').combotree('setValue', row['PRO_EXECUTEDEPTID']);
			$('#userdept').combotree('setText', row['PRO_EXECUTEDEPTNAME']);
			$('#exenameBtn').linkbutton('disable');

			$('#ttUsers').datagrid({
				data : [ {
					"id" : row['PRO_EXECUTEUSERID'],
					"name" : row['PRO_EXECUTEUSERNAME']
				} ],
				columns : [ [ {
					field : 'name',
					title : '用户名',
					width : 150,
					formatter : function(val, rec) {
						return val;
					}
				} ] ]
			});
		}
		function queryForm() {
			var param = {
				"queryname" : $('#queryname').val()
			};
			// 			$('#tttask').datagrid("load", param);
			bindgrid();
		}

		function delForm(rowindex) {
			$.messager.confirm('请确认', '删除后无法恢复，确认删除?', function(r) {
				if (r) {
					var rows = $('#tttask').datagrid("getRows");
					var row = rows[rowindex];
					$.ajax({
						type : "post",
						url : "SurpviseManage/delSurpvise",
						data : {
							infId : row['INF_ID'],
							userId : row['PRO_EXECUTEUSERID'],
							proId : row["PRO_ID"]
						},
						success : function(data) {
							$.messager.alert('消息', data);
							if (data == '删除成功!') {
								bindgrid();
							}
						},
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {
							$.messager.alert('消息', errorThrown);
						}
					});
				}
			});
		}
	</script>
	<!-- 任务详情	 -->
	<script>
		function setExeusers() {
			var name = '';
			var rows = $('#ttUsers').datagrid('getRows');
			for (var i = 0; i < rows.length; i++) {
				var row = rows[i];
				name = name + row["name"];
				if (i < rows.length - 1) {
					name = name + ','
				}
			}
			$('#exename').textbox('setText', name);
		}
		function commit() {
			if (!$('#fm').form('validate')) {
				return;
			}
			var row = $('#tttask').datagrid('getSelected');
			var proId = row == null ? '' : row["PRO_ID"];
			$.messager.confirm('请确认', '提交后无法修改，确认提交?', function(r) {
				if (r) {
					$('.loadinghk').show();
					$.ajax({
						type : "post",
						url : "SurpviseManage/commitSurpvise",
						data : {
							infId : $('#infid').val(),
							name : $('#taskname').textbox('getText'),
							info : $('#taskinfo').val(),
							exeusers : JSON.stringify($('#ttUsers').datagrid(
									'getRows')),
							deptId : $('#userdept').combotree('getValue'),
							deptName : $('#userdept').combotree('getText'),
							proId : proId,
							planDate : $('#datePlan').val()
						},
						success : function(data) {
							$.messager.alert('消息', data);
							if (data == '提交成功!') {
							}
							bindgrid();
							bindgridcurrent();
							bindgriduser();
							$('.loadinghk').hide();
							$('#dlg').dialog('close');
						},
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {
							$('.loadinghk').hide();
							$.messager.alert('消息', errorThrown);
						}
					});
				}
			});
		}

		function save(proId) {
			if (!$('#fm').form('validate')) {
				return;
			}
			$('.loadinghk').show();
			var row = $('#tttask').datagrid('getSelected');
			var proId = row == null ? '' : row["PRO_ID"];
			$.ajax({
				type : "post",
				url : "SurpviseManage/saveSurpvise",
				data : {
					infId : $('#infid').val(),
					name : $('#taskname').textbox('getText'),
					info : $('#taskinfo').val(),
					exeusers : JSON
							.stringify($('#ttUsers').datagrid('getRows')),
					deptId : $('#userdept').combotree('getValue'),
					deptName : $('#userdept').combotree('getText'),
					proId : proId,
					planDate : $('#datePlan').val()
				},
				success : function(data) {
					if (data != '保存失败!') {
						$.messager.alert('消息', "保存成功");
					}
					bindgrid();
					bindgridcurrent();
					// 					bindgriduser();
					$('#dlg').dialog('close');
					$('.loadinghk').hide();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$('.loadinghk').hide();
					$.messager.alert('消息', errorThrown);
				}
			});
		}
	</script>
	<!-- 	执行人 -->
	<script>
		function addQueryUser() {
			var row = $('#ttUserName').datagrid('getSelected');
			if (userisexists(row["id"])) {
				$.messager.alert('消息', '用户已存在');
				return;
			}
			$('#ttUsers').datagrid('appendRow', row);
		}
		function queryUserName() {
			$('#divCurrent').hide();
			$('#divOrg').hide();
			$('#divUserNameGrid').show();
			bindgridQueryName();
		}
		function bindgridQueryName() {
			$('#ttUserName').datagrid({
				title : '',
				singleSelect : true,
				width : 350,
				height : 400,
				url : 'sys/selectUsers',
				queryParams : {
					"queryName" : $('#queryname').val(),
				},
				columns : [ [ {
					field : 'dwmc',
					title : '机构',
					width : 180,
					formatter : function(val, rec) {
						return val;
					}
				}, {
					field : 'name',
					title : '用户名',
					width : 100,
					formatter : function(val, rec) {
						return val;
					}
				} ] ],
				onDblClickRow : function() {
					addQueryUser();
				}
			});
		}
		function saveExe() {
			if (isTransfer == '1') {
				saveTransfer();
			} else {
				setExeusers();
				$('#dlgExe').dialog('close');
			}
		}
		function radioexechange() {
			var checkradio = $("input[name='radioExe']:checked").val();
			if (checkradio == '1') {
				$('#divCurrent').show();
				$('#divOrg').hide();
				$('#divUserNameGrid').hide();
			} else if (checkradio == '2') {
				$('#divCurrent').hide();
				$('#divOrg').show();
				$('#divUserNameGrid').hide();
				bindtreeorg();
			}
		}
		function exeForm() {
			$('#dlgExe').dialog('open').dialog('center').dialog('setTitle',
					'选择执行人');
			// 			$('#fmExe').form('clear');
			$('input:radio:first').attr('checked', 'true');
		}

		function bindtreeorg() {
			$('#ttOrg').treegrid({
				title : '组织机构列表',
				url : 'DeptManage/getDeptChildListJson',
				width : 350,
				height : 400,
				rownumbers : false,
				singleSelect : true,
				idField : 'id',
				treeField : 'name',
				columns : [ [ {
					field : 'name',
					title : '名称',
					width : 300,
					formatter : function(val, rec) {
						return unescape(val)
					}
				} ] ],
				onClickRow : function() {
				},
				onLoadSuccess : function() {
				},
				onDblClickRow : function() {
					adduser();
				}
			});
		}
		function bindgriduser() {
			$('#ttUsers').datagrid({
				title : '已选用户列表',
				singleSelect : true,
				width : 200,
				height : 400,
				data : [],
				columns : [ [ {
					field : 'name',
					title : '用户名',
					width : 150,
					formatter : function(val, rec) {
						return val;
					}
				} ] ]
			});
		}
		function bindgridcurrent() {
			var url = 'SurpviseManage/selectLastUsers';
			if (isTransfer == 1) {
				url = 'SurpviseManage/selectTransferUsers'
			}
			$('#ttCurrent').datagrid({
				title : '常用联系人',
				singleSelect : true,
				width : 350,
				height : 400,
				url : url,
				columns : [ [ {
					field : 'name',
					title : '用户名',
					width : 300,
					formatter : function(val, rec) {
						return val;
					}
				} ] ],
				onDblClickRow : function() {
					adduser();
				}
			});
		}
		function adduser() {
			var checkradio = $("input[name='radioExe']:checked").val();
			var row;
			if (checkradio == '2') {
				row = $('#ttOrg').treegrid('getSelected');
				if (row['propertie'] == 'org') {
					$.messager.alert('消息', '不可选择组织，请选择用户');
					return;
				}
			} else if (checkradio == '1') {
				row = $('#ttCurrent').datagrid('getSelected');
			}
			if (userisexists(row["id"])) {
				$.messager.alert('消息', '用户已存在');
				return;
			}
			$('#ttUsers').datagrid('appendRow', row);
		}
		function deluser() {
			var row = $('#ttUsers').datagrid('getSelected');
			if (row == null) {
				$.messager.alert('消息', '请选择用户');
				return;
			}
			var index = $('#ttUsers').datagrid('getRowIndex', row);
			$('#ttUsers').datagrid('deleteRow', index);
		}
		//用户是否已存在
		function userisexists(userid) {
			var flag = false;
			var rows = $('#ttUsers').datagrid('getRows');
			for (var i = 0; i < rows.length; i++) {
				var row = rows[i];
				if (row["id"] == userid) {
					return true;
				}
			}
			return flag;
		}
	</script>
</body>
</html>